package com.yonyou.cyxdms.sysAuth.service.controller.dealerchannel;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yonyou.cyx.framework.controller.base.BaseController;
import com.yonyou.cyx.framework.service.excel.ExcelDataType;
import com.yonyou.cyx.framework.service.excel.ExcelExportColumn;
import com.yonyou.cyx.framework.service.excel.ExcelGenerator;
import com.yonyou.cyxdms.sysAuth.service.dto.dealerchannel.TmDealerchannelDTO;
import com.yonyou.cyxdms.sysAuth.service.service.dealerchannel.DealerChannelService;
import com.yonyou.cyxdms.sysAuth.service.vo.dealerchannel.DealerChannelDetailVO;
import com.yonyou.cyxdms.sysAuth.service.vo.dealerchannel.DealerChannelVO;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/dealerChannel")
public class DealerChannelController extends BaseController {

    @Autowired
    private DealerChannelService dealerChannelService;

    @Autowired
    private ExcelGenerator excelService;

    // 定义日志接口
    private static final Logger logger = LoggerFactory.getLogger(DealerChannelController.class);

    /**
     * 修改经销商渠道信息
     *
     * @author dengqiang
     * @since 2019/7/23
     */
    @PostMapping(value = "/editDealerChannel/{id}")
    @ResponseBody
    public Integer editDealerChannel(@PathVariable Long id, @RequestBody TmDealerchannelDTO dealerDto) {
        return dealerChannelService.editDealerChannel(id, dealerDto);
    }


    /**
     * 按照ID查询经销商信息
     *
     * @author dengqiang
     * @since 2019/7/24
     */
    @GetMapping(value = "/getDealerChannelByID/{id}")
    @ResponseBody
    public DealerChannelDetailVO getCustomerReoAccount(@PathVariable(value = "id") Long id) {
        return dealerChannelService.getDealerChannelById(id);
    }

    /**
     * 导出经销商信息
     *
     * @author dengqiang
     * @since 2019/7/24
     */
    @SuppressWarnings("rawtypes")
    @GetMapping(value = "/export/excel")
    public void exportDealerInfos(@RequestParam Map<String, String> queryParam, HttpServletRequest request,
                                  HttpServletResponse response) {
        List<Map> resultList = dealerChannelService.queryDealerInfoExport(queryParam);
        Map<String, List<Map>> excelData = new HashMap<>();
        excelData.put("经销商公司信息", resultList);
        List<ExcelExportColumn> exportColumnList = new ArrayList<>();
        exportColumnList.add(new ExcelExportColumn("dealerCompanyId", "经销商公司代码"));
        exportColumnList.add(new ExcelExportColumn("salesAuthority", "销售权限", ExcelDataType.Dict));
        exportColumnList.add(new ExcelExportColumn("afterSaleAuthority", "售后权限", ExcelDataType.Dict));
        exportColumnList.add(new ExcelExportColumn("customerType", "客户类型", ExcelDataType.Dict));
        exportColumnList.add(new ExcelExportColumn("salesOrganization", "销售组织", ExcelDataType.Dict));
        exportColumnList.add(new ExcelExportColumn("designatedAfterSalesDeale", "指定售后经销商"));
        exportColumnList.add(new ExcelExportColumn("salesAreaName", "销售大区"));
        exportColumnList.add(new ExcelExportColumn("AftersaleAreaName", "售后大区"));
        exportColumnList.add(new ExcelExportColumn("salesCode", "销售代码"));
        exportColumnList.add(new ExcelExportColumn("afterSaleCode", "售后代码"));
        exportColumnList.add(new ExcelExportColumn("dealerName", "工商注册名称"));
        exportColumnList.add(new ExcelExportColumn("address", "公司地址"));
        exportColumnList.add(new ExcelExportColumn("shortName", "店面简称"));
        exportColumnList.add(new ExcelExportColumn("bzirk", "大区", ExcelDataType.Dict));
        exportColumnList.add(new ExcelExportColumn("kdgrp", "店面级别", ExcelDataType.Dict));
        exportColumnList.add(new ExcelExportColumn("taxnumxl", "纳税人识别号"));
        exportColumnList.add(new ExcelExportColumn("homeCity", "工商备案电话"));
        exportColumnList.add(new ExcelExportColumn("houseNum2", "联系人（总经理）"));
        exportColumnList.add(new ExcelExportColumn("mobileNumber", "联系方式"));
        exportColumnList.add(new ExcelExportColumn("accountBankName", "税局备案银行开户行名称"));
        exportColumnList.add(new ExcelExportColumn("bankAccount", "税局备案银行账号"));
        exportColumnList.add(new ExcelExportColumn("street", "税局备案地址"));
        exportColumnList.add(new ExcelExportColumn("telNumber", "税局备案电话"));
        exportColumnList.add(new ExcelExportColumn("salesAccountBankName", "销售银行开户名称"));
        exportColumnList.add(new ExcelExportColumn("salesAccountBank", "银行账号：销售"));
        exportColumnList.add(new ExcelExportColumn("afterSalesAccountBankName", "售后银行开户名称"));
        exportColumnList.add(new ExcelExportColumn("afterSalesAccountBank", "银行账号：售后"));
        exportColumnList.add(new ExcelExportColumn("building", "财务负责人电话"));
        exportColumnList.add(new ExcelExportColumn("location", "发票邮寄收件人"));
        exportColumnList.add(new ExcelExportColumn("city2", "发票邮寄收件电话"));
        exportColumnList.add(new ExcelExportColumn("strSuppl2", "发票邮寄地址"));
        exportColumnList.add(new ExcelExportColumn("strSuppl3", "零件接收地址"));
        exportColumnList.add(new ExcelExportColumn("roomnumber", "零件接收联系人"));
        exportColumnList.add(new ExcelExportColumn("nameCo", "零件接收联系电话"));
        exportColumnList.add(new ExcelExportColumn("floor", "紧急联系人"));
        exportColumnList.add(new ExcelExportColumn("strSuppl1", "紧急联系电话"));
        exportColumnList.add(new ExcelExportColumn("houseNum1", "DMS系统管理员"));
        exportColumnList.add(new ExcelExportColumn("bahns", "管理员联系电话"));
        exportColumnList.add(new ExcelExportColumn("katr1", "网络供应商", ExcelDataType.Dict));
        exportColumnList.add(new ExcelExportColumn("katr2", "网络类型", ExcelDataType.Dict));
        exportColumnList.add(new ExcelExportColumn("katr3", "网络宽带", ExcelDataType.Dict));
        exportColumnList.add(new ExcelExportColumn("locco", "使用人数"));
        exportColumnList.add(new ExcelExportColumn("smtpAddr", "网管邮箱地址"));
        exportColumnList.add(new ExcelExportColumn("freeze", "冻结标识", ExcelDataType.Dict));
        logger.debug("exportColumnList:{}", exportColumnList);
        logger.debug("excelData:{}", excelData);
        excelService.generateExcel(excelData, exportColumnList, "经销商公司信息.xls", request, response);
    }


}
